package org.jeecg.modules.assets.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.assets.entity.AssetsDoubleQuotationResultItem;
import org.jeecg.modules.assets.entity.AssetsExpansion;
import org.jeecg.modules.assets.entity.AssetsItem;
import org.jeecg.modules.assets.entity.AssetsPreliminaryResultsItem;
import org.jeecg.modules.assets.mapper.AssetsExpansionMapper;
import org.jeecg.modules.assets.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 资产扩展信息管理
 * @Author: jeecg-boot
 * @Date: 2024-01-03
 * @Version: V1.0
 */
@Service
public class AssetsExpansionServiceImpl extends ServiceImpl<AssetsExpansionMapper, AssetsExpansion> implements IAssetsExpansionService {

    @Autowired
    private IAssetsItemService assetsItemService;
    @Autowired
    private IAssetsPreliminaryResultsItemService  assetsPreliminaryResultsItemService;

    @Autowired
    private IAssetsDoubleQuotationResultItemService assetsDoubleQuotationResultItemService;

    @Override
    public void updateAssetsExpansion(AssetsExpansion assetsExpansion) {
        switch(assetsExpansion.getUpdateType()){
            case 1:
                break;
            case 2:
                //初盘
                AssetsPreliminaryResultsItem assetsPreliminaryResultsItem = new AssetsPreliminaryResultsItem();
                assetsPreliminaryResultsItem.setId(assetsExpansion.getId());
                assetsPreliminaryResultsItem.setAssetsLocation(assetsExpansion.getLocation());
                assetsPreliminaryResultsItemService.updateById(assetsPreliminaryResultsItem);
                break;
            case 3:
                //复盘信息
                AssetsDoubleQuotationResultItem assetsDoubleQuotationResultItem = new AssetsDoubleQuotationResultItem();
                assetsDoubleQuotationResultItem.setId(assetsExpansion.getId());
                assetsDoubleQuotationResultItem.setAssetsLocation(assetsExpansion.getLocation());
                assetsDoubleQuotationResultItemService.updateById(assetsDoubleQuotationResultItem);
                break;
                case 4:
                //抽盘信息

            default:
                break;
        }
        QueryWrapper qw = new QueryWrapper();
        qw.eq("asset_coding", assetsExpansion.getAssetCoding());
        qw.eq("company", assetsExpansion.getCompany());
        AssetsItem item = assetsItemService.getOne(qw);
        if (item == null) {
            throw new RuntimeException("资产不存在");
        }
        item.setAssetsLocation(assetsExpansion.getLocation());
        assetsItemService.updateById(item);
        QueryWrapper qMt = new QueryWrapper();
        qMt.eq("asset_coding", assetsExpansion.getAssetCoding());
        qMt.eq("company", assetsExpansion.getCompany());
        AssetsExpansion one = this.getOne(qMt);
        if(one!=null){
            one.setLocation(assetsExpansion.getLocation());
            this.updateById(one);
        }else {
            one = new AssetsExpansion();
            one.setAssetCoding(assetsExpansion.getAssetCoding());
            one.setLocation(assetsExpansion.getLocation());
            this.save(one);
        }




    }
}
